home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / make-367.lha / make-3.67 / default.c < prev    next >
C/C++ Source or Header  |  1993-04-15  |  9KB  |  354 lines

  1. /* Data base of default implicit rules for GNU Make.
  2. Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "rule.h"
  21. #include "dep.h"
  22. #include "file.h"
  23. #include "commands.h"
  24. #include "variable.h"
  25.  
  26.  
  27. /* This is the default list of suffixes for suffix rules.
  28.    `.s' must come last, so that a `.o' file will be made from
  29.    a `.c' or `.p' or ... file rather than from a .s file.  */
  30.  
  31. static char default_suffixes[]
  32.   = ".out .a .ln .o .c .cc .C .p .f .F .r .y .l .s .S \
  33. .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
  34. .cweb .web .sh .elc .el";
  35.  
  36. static struct pspec default_pattern_rules[] =
  37.   {
  38.     { "(%)", "%",
  39.     "$(AR) $(ARFLAGS) $@ $<" },
  40.  
  41.     /* The X.out rules are only in BSD's default set because
  42.        BSD Make has no null-suffix rules, so `foo.out' and
  43.        `foo' are the same thing.  */
  44.     { "%.out", "%",
  45.     "@rm -f $@ \n cp $< $@" },
  46.  
  47.     { 0, 0, 0 }
  48.   };
  49.  
  50. static struct pspec default_terminal_rules[] =
  51.   {
  52.     /* RCS.  */
  53.     { "%", "%,v",
  54.     "+$(CHECKOUT,v)" },
  55.     { "%", "RCS/%,v",
  56.     "+$(CHECKOUT,v)" },
  57.  
  58.     /* SCCS.  */
  59.     { "%", "s.%",
  60.     "$(GET) $(GFLAGS) $<" },
  61.     { "%", "SCCS/s.%",
  62.     "$(GET) $(GFLAGS) $<" },
  63.  
  64.     { 0, 0, 0 }
  65.   };
  66.  
  67. static char *default_suffix_rules[] =
  68.   {
  69.     ".o",
  70.     "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  71.     ".s",
  72.     "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  73.     ".S",
  74.     "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  75.     ".c",
  76.     "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  77.     ".cc",
  78.     "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  79.     ".C",
  80.     "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  81.     ".f",
  82.     "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  83.     ".p",
  84.     "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  85.     ".F",
  86.     "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  87.     ".r",
  88.     "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  89.     ".mod",
  90.     "$(COMPILE.mod) -o $@ -e $@ $^",
  91.  
  92.     ".def.sym", 
  93.     "$(COMPILE.def) -o $@ $<",
  94.  
  95.     ".sh",
  96.     "cat $< >$@ \n chmod a+x $@",
  97.  
  98.     ".s.o",
  99. #if !defined(M_XENIX) || defined(__GNUC__)
  100.     "$(COMPILE.s) -o $@ $<",
  101. #else    /* Xenix.  */
  102.     "$(COMPILE.s) -o$@ $<",
  103. #endif    /* Not Xenix.  */
  104.     ".S.o",
  105. #if !defined(M_XENIX) || defined(__GNUC__)
  106.     "$(COMPILE.S) -o $@ $<",
  107. #else    /* Xenix.  */
  108.     "$(COMPILE.S) -o$@ $<",
  109. #endif    /* Not Xenix.  */
  110.     ".c.o",
  111.     "$(COMPILE.c) $< $(OUTPUT_OPTION)",
  112.     ".cc.o",
  113.     "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
  114.     ".C.o",
  115.     "$(COMPILE.C) $< $(OUTPUT_OPTION)",
  116.     ".f.o",
  117.     "$(COMPILE.f) $< $(OUTPUT_OPTION)",
  118.     ".p.o",
  119.     "$(COMPILE.p) $< $(OUTPUT_OPTION)",
  120.     ".F.o",
  121.     "$(COMPILE.F) $< $(OUTPUT_OPTION)",
  122.     ".r.o",
  123.     "$(COMPILE.r) $< $(OUTPUT_OPTION)",
  124.     ".mod.o",
  125.     "$(COMPILE.mod) -o $@ $<",
  126.  
  127.     ".c.ln",
  128.     "$(LINT.c) -C$* $<",
  129.     ".y.ln",
  130.     "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
  131.     ".l.ln",
  132.     "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
  133.  
  134.     ".y.c",
  135.     "$(YACC.y) $< \n mv -f y.tab.c $@",
  136.     ".l.c",
  137.     "@$(RM) $@ \n $(LEX.l) $< > $@",
  138.  
  139.     ".F.f",
  140.     "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
  141.     ".r.f",
  142.     "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
  143.  
  144.     /* This might actually make lex.yy.c if there's no %R%
  145.        directive in $*.l, but in that case why were you
  146.        trying to make $*.r anyway?  */
  147.     ".l.r",
  148.     "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
  149.  
  150.     ".S.s",
  151.     "$(PREPROCESS.S) $< > $@",
  152.  
  153.     ".texinfo.info",
  154.     "$(MAKEINFO) $< -o $@",
  155.  
  156.     ".texi.info",
  157.     "$(MAKEINFO) $< -o $@",
  158.  
  159.     ".txinfo.info",
  160.     "$(MAKEINFO) $< -o $@",
  161.  
  162.     ".tex.dvi",
  163.     "$(TEX) $<",
  164.  
  165.     ".texinfo.dvi",
  166.     "$(TEXI2DVI) $<",
  167.  
  168.     ".texi.dvi",
  169.     "$(TEXI2DVI) $<",
  170.  
  171.     ".txinfo.dvi",
  172.     "$(TEXI2DVI) $<",
  173.  
  174.     ".cweb.c",
  175.     "$(CTANGLE) $<",
  176.  
  177.     ".web.p",
  178.     "$(TANGLE) $<",
  179.  
  180.     ".cweb.tex",
  181.     "$(CWEAVE) $<",
  182.  
  183.     ".web.tex",
  184.     "$(WEAVE) $<",
  185.  
  186.     0, 0,
  187.   };
  188.  
  189. static char *default_variables[] =
  190.   {
  191.     "AR", "ar",
  192.     "ARFLAGS", "rv",
  193.     "AS", "as",
  194.     "CC", "cc",
  195.     "CXX", "g++",
  196.  
  197.     /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
  198.        and to the empty string if $@ does exist.  */
  199.     "CHECKOUT,v",
  200.     "$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
  201.         $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
  202.  
  203.     "CO", "co",
  204.     "CPP", "$(CC) -E",
  205. #ifdef    CRAY
  206.     "CF77PPFLAGS", "-P",
  207.     "CF77PP", "/lib/cpp",
  208.     "CFT", "cft77",
  209.     "CF", "cf77",
  210.     "FC", "$(CF)",
  211. #else    /* Not CRAY.  */
  212. #ifdef    _IBMR2
  213.     "FC", "xlf",
  214. #else
  215. #ifdef    __convex__
  216.     "FC", "fc",
  217. #else
  218.     "FC", "f77",
  219. #endif /* __convex__ */
  220. #endif /* _IBMR2 */
  221.     /* System V uses these, so explicit rules using them should work.
  222.        However, there is no way to make implicit rules use them and FC.  */
  223.     "F77", "$(FC)",
  224.     "F77FLAGS", "$(FFLAGS)",
  225. #endif    /* Cray.  */
  226.     "GET", SCCS_GET,
  227.     "LD", "ld",
  228.     "LEX", "lex",
  229.     "LINT", "lint",
  230.     "M2C", "m2c",
  231. #ifdef    pyr
  232.     "PC", "pascal",
  233. #else
  234. #ifdef    CRAY
  235.     "PC", "PASCAL",
  236.     "SEGLDR", "segldr",
  237. #else
  238.     "PC", "pc",
  239. #endif    /* CRAY.  */
  240. #endif    /* pyr.  */
  241.     "YACC", "yacc",    /* Or "bison -y"  */
  242.     "MAKEINFO", "makeinfo",
  243.     "TEX", "tex",
  244.     "TEXI2DVI", "texi2dvi",
  245.     "WEAVE", "weave",
  246.     "CWEAVE", "cweave",
  247.     "TANGLE", "tangle",
  248.     "CTANGLE", "ctangle",
  249.  
  250.     "RM", "rm -f",
  251.  
  252.     "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
  253.     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  254.     "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  255.     "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  256.     "COMPILE.C", "$(COMPILE.cc)",
  257.     "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  258.     "LINK.C", "$(LINK.cc)",
  259.     "YACC.y", "$(YACC) $(YFLAGS)",
  260.     "LEX.l", "$(LEX) $(LFLAGS) -t",
  261.     "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
  262.     "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  263.     "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  264.     "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  265.     "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
  266.     "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  267.     "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
  268.     "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
  269.     "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  270.     "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  271.     "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  272.     "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
  273.     "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  274.     "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
  275. #if !defined(M_XENIX) || defined(__GNUC__)
  276.     "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
  277. #else    /* Xenix.  */
  278.     "PREPROCESS.S", "$(CC) -EP $(CPPFLAGS)",
  279. #endif    /* Not Xenix.  */
  280.     "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
  281.     "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
  282.     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  283.  
  284. #ifndef    NO_MINUS_C_MINUS_O
  285. #if !defined(M_XENIX) || defined(__GNUC__)
  286.     "OUTPUT_OPTION", "-o $@",
  287. #else    /* Xenix.  */
  288.     "OUTPUT_OPTION", "-Fo$@",
  289. #endif    /* Not Xenix.  */
  290. #endif
  291.  
  292.     0, 0
  293.   };
  294.  
  295. /* Set up the default .SUFFIXES list.  */
  296.  
  297. void
  298. set_default_suffixes ()
  299. {
  300.   suffix_file = enter_file (".SUFFIXES");
  301.  
  302.   if (no_builtin_rules_flag)
  303.     (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
  304.   else
  305.     {
  306.       char *p = default_suffixes;
  307.       suffix_file->deps = (struct dep *)
  308.     multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep)),
  309.             sizeof (struct dep), 1);
  310.       (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
  311.     }
  312. }
  313.  
  314. /* Install the default pattern rules and enter
  315.    the default suffix rules as file rules.  */
  316.  
  317. void
  318. install_default_implicit_rules ()
  319. {
  320.   register struct pspec *p;
  321.   register char **s;
  322.   
  323.   if (no_builtin_rules_flag)
  324.     return;
  325.  
  326.   for (p = default_pattern_rules; p->target != 0; ++p)
  327.     install_pattern_rule (p, 0);
  328.  
  329.   for (p = default_terminal_rules; p->target != 0; ++p)
  330.     install_pattern_rule (p, 1);
  331.  
  332.   for (s = default_suffix_rules; *s != 0; s += 2)
  333.     {
  334.       register struct file *f = enter_file (s[0]);
  335.       /* Don't clobber cmds given in a makefile if there were any.  */
  336.       if (f->cmds == 0)
  337.     {
  338.       f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
  339.       f->cmds->filename = 0;
  340.       f->cmds->commands = s[1];
  341.       f->cmds->command_lines = 0;
  342.     }
  343.     }
  344. }
  345.  
  346. void
  347. define_default_variables ()
  348. {
  349.   register char **s;
  350.  
  351.   for (s = default_variables; *s != 0; s += 2)
  352.     (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
  353. }
  354.